/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfoorder.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfoorder.entity.CampusinfoOrder;
import com.lczyfz.campusinfo.modules.campusinfoorder.service.CampusinfoOrderService;

/**
 * 订单号Controller
 * @author zms
 * @version 2018-05-13
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfoorder/campusinfoOrder")
public class CampusinfoOrderController extends BaseController {

	@Autowired
	private CampusinfoOrderService campusinfoOrderService;

	@ModelAttribute
	public CampusinfoOrder get(@RequestParam(required=false) String id) {
		CampusinfoOrder entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = campusinfoOrderService.get(id);
		}
		if (entity == null){
			entity = new CampusinfoOrder();
		}
		return entity;
	}
	
	@RequiresPermissions("campusinfoorder:campusinfoOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(CampusinfoOrder campusinfoOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoOrder> page = campusinfoOrderService.findPage(new Page<CampusinfoOrder>(request, response), campusinfoOrder); 
		model.addAttribute("page", page);
		return "modules/campusinfoorder/campusinfoOrderList";
	}

	@RequiresPermissions("campusinfoorder:campusinfoOrder:view")
	@RequestMapping(value = "form")
	public String form(CampusinfoOrder campusinfoOrder, Model model) {
		model.addAttribute("campusinfoOrder", campusinfoOrder);
		return "modules/campusinfoorder/campusinfoOrderForm";
	}

	@RequiresPermissions("campusinfoorder:campusinfoOrder:edit")
	@RequestMapping(value = "save")
	public String save(CampusinfoOrder campusinfoOrder, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, campusinfoOrder)){
			return form(campusinfoOrder, model);
		}
		campusinfoOrderService.save(campusinfoOrder);
		addMessage(redirectAttributes, "保存订单号成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfoorder/campusinfoOrder/?repage";
	}
	
	@RequiresPermissions("campusinfoorder:campusinfoOrder:edit")
	@RequestMapping(value = "delete")
	public String delete(CampusinfoOrder campusinfoOrder, RedirectAttributes redirectAttributes) {
		campusinfoOrderService.delete(campusinfoOrder);
		addMessage(redirectAttributes, "删除订单号成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfoorder/campusinfoOrder/?repage";
	}

}